extends Node2D

# 雾天效果属性
@export var duration: float = 12.0  # 雾天持续时间
@export var vision_reduction_factor: float = 0.5  # 视野减少因子

var time_alive: float = 0.0
var max_alpha: float = 0.7  # 最大透明度

func _ready():
	# 设置初始透明度
	modulate.a = 0.0
	
	# 设置大小覆盖整个屏幕
	var viewport_size = get_viewport_rect().size
	$Sprite2D.scale = Vector2(viewport_size.x / 100, viewport_size.y / 100)
	
	# 播放音效（如果有）
	if has_node("AudioStreamPlayer2D"):
		$AudioStreamPlayer2D.play()
	
	# 淡入效果
	var tween = create_tween()
	tween.tween_property(self, "modulate:a", max_alpha, 2.0)

func _process(delta):
	# 更新生命周期
	time_alive += delta
	
	# 到达最大存活时间后消失
	if time_alive >= duration:
		# 淡出效果
		var tween = create_tween()
		tween.tween_property(self, "modulate:a", 0.0, 2.0)
		tween.tween_callback(queue_free)
